package com.pkk.penguin.frame.know.java.interview.year2021.expand;

import static com.sun.xml.internal.fastinfoset.util.ValueArray.MAXIMUM_CAPACITY;

import java.util.HashMap;
import org.junit.Test;

/**
 * hashmap的扩展
 *
 * @author peikunkun
 * @version V1.0
 * @date 2021-03-06 13:55
 **/
public class HashMapExpand {

  @Test
  public void Administrator_18_20210308112808_() {
    System.out.println("欢迎使用单元测试方法【Administrator_18()_20210308112808】");
    System.out.println("此方法测试描述：【】");
    final HashMap<Object, Object> map2 = new HashMap<>(3);
    map2.put("aaa","bbb");
  }



  @Test
  public void Administrator_14_20210306135652_() {
    System.out.println("欢迎使用单元测试方法【Administrator_14()_20210306135652】");
    System.out.println("此方法测试描述：【】");
    final HashMap<Object, Object> map1 = new HashMap<>();
    final HashMap<Object, Object> map2 = new HashMap<>(3);
    System.out.println((1 << 31));
    System.out.println(Integer.toBinaryString(1 << 31));
    System.out.println(((1 << 31) - 1));
    System.out.println((Integer.toBinaryString((1 << 31) - 1)));

    System.out.println("按位或(|=)");
    int n = 6;
    System.out.println(Integer.toBinaryString(n));
    System.out.println(Integer.toBinaryString(n | n >>> 1));
    n |= n >>> 1;
    System.out.println(Integer.toBinaryString(n | n >>> 2));
    n |= n >>> 2;
    System.out.println(Integer.toBinaryString(n | n >>> 4));
    n |= n >>> 4;
    System.out.println(Integer.toBinaryString(n | n >>> 8));
    n |= n >>> 8;
    System.out.println(Integer.toBinaryString(n | n >>> 16));
    n |= n >>> 16;
    System.out.println(Integer.toBinaryString(n));

    System.out.println("----------------");
    int q = 6;
    System.out.println(Integer.toBinaryString(q));
    System.out.println(Integer.toBinaryString(q >>> 1));
    System.out.println(Integer.toBinaryString(q));
    System.out.println("-----------------------");

    int b = 6;
    b |= b >>> 1;
    b |= b >>> 2;
    b |= b >>> 4;
    b |= b >>> 8;
    b |= b >>> 16;
    System.out.println(Integer.toBinaryString(b));
    System.out.println(b);

    System.out.println(tableSizeFor(6));

  }


  static final int tableSizeFor(int cap) {
    int n = cap - 1;
    n |= n >>> 1;
    n |= n >>> 2;
    n |= n >>> 4;
    n |= n >>> 8;
    n |= n >>> 16;
    return (n < 0) ? 1 : (n >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : n + 1;
  }

}
